<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Jar Upload</title>
</head>
<body>
<h1>欢迎来到Jarvis</h1>
请上传完整jar包
<input type="file" name="file" id="jarFile">
<button onclick="clickBtn()">点击</button>
<div id="uploadStatus">请选择jar包</div>
<div id="oldJarClean"></div>
<div id="newJarStart"></div>
<div id="progress"></div>

<script>
    function clickBtn() {
        const oldJarClean = document.querySelector("#oldJarClean")
        const newJarStart = document.querySelector("#newJarStart")
        oldJarClean.innerHTML = "";
        newJarStart.innerHTML = "";
        const uploadStatus = document.querySelector("#uploadStatus")
        uploadStatus.innerHTML = "文件正在上传......"
        const progress = document.querySelector("#progress");
        progress.innerHTML = "发布进度 0 %";
        const event = document.querySelector("#jarFile")
        const formData = new FormData()
        formData.append("file", event.files[0])
        const xhr = new XMLHttpRequest()
        xhr.open("post", "/upload", true)
        let rate = 5;
        var interval = setInterval(function () {
            progress.innerHTML = "发布进度 " + rate + " %";
            if (rate >= 95) {
                rate = 99;
            } else {
                rate = rate + 5;
            }
            if (rate >= 70 && rate <= 80) {
                uploadStatus.innerHTML = "文件上传成功 !"
                oldJarClean.innerHTML = "正在关闭旧项目......"
            }
            if (rate >= 85) {
                uploadStatus.innerHTML = "文件上传成功 !"
                oldJarClean.innerHTML = "旧项目关闭成功 !"
                newJarStart.innerHTML = "正在启动新项目......"
            }
        }, 2000)
        xhr.onreadystatechange = function () {
            if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                uploadStatus.innerHTML = "文件上传成功 !"
                oldJarClean.innerHTML = "旧项目关闭成功 !"
                newJarStart.innerHTML = "项目发布成功 !"
                clearInterval(interval);
                progress.innerHTML = "发布进度 100 %";
            }
        }
        xhr.send(formData)
    }
</script>
</body>
</html>